/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.p2psimulator.analysis;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.p2psimulator.config.ThreadConfig;

/**
 *
 * @author Amorim
 */
public abstract class InfoCollector <T, V>{

    ExecutorService executorService;

    public InfoCollector() {
        executorService = Executors.newFixedThreadPool(ThreadConfig.MAX_EVENT_THREADS);
    }

    public abstract void collectInfo(T t, V v);


    public void runInfoCollector(T t, V v){
        CollectorThread thread = new CollectorThread(t, v);
        executorService.submit(thread);
    }
    public void shutdownColletor(){
        executorService.shutdown();
    }
    public void initCollector(){
        executorService = Executors.newFixedThreadPool(ThreadConfig.MAX_EVENT_THREADS);
    }
    
    class CollectorThread implements Runnable{

        T t;
        V v;
        public CollectorThread(T t, V v) {
            this.t = t;
            this.v = v;
        }

        public void run(){
            collectInfo(t, v);
        }
    }
}
